#include "Shooter_PCH.h"
#include "Texture.h"

/*--------------------------------------------------------------------------*/

Texture::Texture(const std::string& name, const std::string& path) :
	IResource(name)
{
	m_handle = SOIL_load_OGL_texture(	path.c_str(),
										SOIL_LOAD_AUTO,
										SOIL_CREATE_NEW_ID,
										SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT);

	if (m_handle == 0) 
	{
		std::cout << "Failed to load texture: " << path << std::endl;
		std::cout << "Loading data/img/replaceme.png" << std::endl;

		m_handle = SOIL_load_OGL_texture(	"../data/img/replaceme.png",
											SOIL_LOAD_AUTO,
											SOIL_CREATE_NEW_ID,
											SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT);
	}
	else
	{
		std::cout << "Loaded texture: " << path << std::endl;
	}
}

/*--------------------------------------------------------------------------*/

Texture::~Texture()
{
	glDeleteTextures(1, &m_handle);
	m_handle = 0;
}

/*--------------------------------------------------------------------------*/

unsigned int Texture::GetHandle() const
{
	return m_handle;
}

/*--------------------------------------------------------------------------*/
